package org.jeecg.modules.demo.ch.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.demo.ch.common.PageList;
import org.jeecg.modules.demo.ch.entity.ChSoftwareOperationPlan;
import org.jeecg.modules.demo.ch.entity.ChSoftwareOperationPlanReport;
import org.jeecg.modules.demo.ch.service.IChSoftwareOperationPlanReportService;
import org.jeecg.modules.demo.ch.service.IChSoftwareOperationPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 软件运维报表
 * @Author: jeecg-boot
 * @Date: 2022-10-27
 * @Version: V1.0
 */
@Api(tags = "软件运维报表")
@RestController
@RequestMapping("/ch/chSoftwareOperationPlanReport")
@Slf4j
public class ChSoftwareOperationPlanReportController extends JeecgController<ChSoftwareOperationPlanReport, IChSoftwareOperationPlanReportService> {
    @Autowired
    private IChSoftwareOperationPlanReportService chSoftwareOperationPlanReportService;

    @Autowired
    private IChSoftwareOperationPlanService chSoftwareOperationPlanService;

    /**
     * 分页列表查询
     *
     * @param chSoftwareOperationPlanReport
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "软件运维报表-分页列表查询")
    @ApiOperation(value = "软件运维报表-分页列表查询", notes = "软件运维报表-分页列表查询")
    @GetMapping(value = "/list")
    public Result<PageList<ChSoftwareOperationPlan>> queryPageList(ChSoftwareOperationPlanReport chSoftwareOperationPlanReport,
                                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                               String authorizationDeadlineBegin,
                                                               String authorizationDeadlineEnd,
                                                               String hardwareAuthorizationDeadlineBegin,
                                                               String hardwareAuthorizationDeadlineEnd,
                                                               String hardExpirBeginTime,
                                                               String hardExpirEndTime,
                                                               String softExpirBeginTime,
                                                               String softExpirEndTime,
                                                               HttpServletRequest req) {
        log.info("传来的参数authorizationDeadlineBegin:{} authorizationDeadlineEnd:{} hardwareAuthorizationDeadlineBegin:{} hardwareAuthorizationDeadlineEnd:{},hardExpirBeginTime:{},hardExpirEndTime:{},softExpirBeginTime:{},softExpirEndTime:{}",authorizationDeadlineBegin,authorizationDeadlineEnd,hardwareAuthorizationDeadlineBegin,hardwareAuthorizationDeadlineEnd,hardExpirBeginTime,hardExpirEndTime,softExpirBeginTime,softExpirEndTime);
        int num = chSoftwareOperationPlanService.selectChSoftwareOperationPlanListTotalByTime(authorizationDeadlineBegin, authorizationDeadlineEnd,hardwareAuthorizationDeadlineBegin,hardwareAuthorizationDeadlineEnd,hardExpirBeginTime,hardExpirEndTime,softExpirBeginTime,softExpirEndTime);
        PageList<ChSoftwareOperationPlan> chSoftwareOperationPlanPageList = new PageList<>(pageNo,pageSize,num);
        List<ChSoftwareOperationPlan> chSoftwareOperationPlanList = chSoftwareOperationPlanService.selectChSoftwareOperationPlanListByTime(pageNo, pageSize, authorizationDeadlineBegin, authorizationDeadlineEnd,hardwareAuthorizationDeadlineBegin,hardwareAuthorizationDeadlineEnd,hardExpirBeginTime,hardExpirEndTime,softExpirBeginTime,softExpirEndTime);
        chSoftwareOperationPlanPageList.setRecords(chSoftwareOperationPlanList);
        return Result.OK(chSoftwareOperationPlanPageList);
    }

    /**
     * 添加
     *
     * @param chSoftwareOperationPlanReport
     * @return
     */
    @AutoLog(value = "软件运维报表-添加")
    @ApiOperation(value = "软件运维报表-添加", notes = "软件运维报表-添加")
    //@RequiresPermissions("org.jeecg.modules.demo:ch_software_operation_plan_report:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody ChSoftwareOperationPlanReport chSoftwareOperationPlanReport) {
        chSoftwareOperationPlanReportService.save(chSoftwareOperationPlanReport);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param chSoftwareOperationPlanReport
     * @return
     */
    @AutoLog(value = "软件运维报表-编辑")
    @ApiOperation(value = "软件运维报表-编辑", notes = "软件运维报表-编辑")
    //@RequiresPermissions("org.jeecg.modules.demo:ch_software_operation_plan_report:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody ChSoftwareOperationPlanReport chSoftwareOperationPlanReport) {
        chSoftwareOperationPlanReportService.updateById(chSoftwareOperationPlanReport);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "软件运维报表-通过id删除")
    @ApiOperation(value = "软件运维报表-通过id删除", notes = "软件运维报表-通过id删除")
    //@RequiresPermissions("org.jeecg.modules.demo:ch_software_operation_plan_report:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        chSoftwareOperationPlanReportService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "软件运维报表-批量删除")
    @ApiOperation(value = "软件运维报表-批量删除", notes = "软件运维报表-批量删除")
    //@RequiresPermissions("org.jeecg.modules.demo:ch_software_operation_plan_report:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.chSoftwareOperationPlanReportService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "软件运维报表-通过id查询")
    @ApiOperation(value = "软件运维报表-通过id查询", notes = "软件运维报表-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ChSoftwareOperationPlanReport> queryById(@RequestParam(name = "id", required = true) String id) {
        ChSoftwareOperationPlanReport chSoftwareOperationPlanReport = chSoftwareOperationPlanReportService.getById(id);
        if (chSoftwareOperationPlanReport == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(chSoftwareOperationPlanReport);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param chSoftwareOperationPlanReport
     */
    //@RequiresPermissions("org.jeecg.modules.demo:ch_software_operation_plan_report:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, ChSoftwareOperationPlanReport chSoftwareOperationPlanReport) {
        return super.exportXls(request, chSoftwareOperationPlanReport, ChSoftwareOperationPlanReport.class, "软件运维报表");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("ch_software_operation_plan_report:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, ChSoftwareOperationPlanReport.class);
    }

}
